package weaponrelated;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JLabel;

import planes.enemy;
import GAME.game;
import planes.*;

public class bullet extends JLabel{
	protected game juego;
	protected int speed;
	protected int potencia;
	protected boolean up;
	protected boolean down;
	protected boolean left;
	protected boolean right;
	public bullet(game g,int pot,int vel){
		potencia=pot;
		juego=g;
		speed=vel;
		up=false;
		down=false;
		left=false;
		right=false;
	}
	public void setmovimiento(boolean d,boolean l,boolean r,boolean u){ //setea el tipo de movimiento de la bala
		down=d;
		left=l;
		right=r;
		up=u;
	}
	public void mover(){
		Point pos=this.getLocation();
		if(up && !down && !left && !right){ //mov arriva
		
				int v = pos.y - speed;
				pos.setLocation(pos.x, v);
			
				
		}
		if(down && !up && !left && !right){ // mov abajo
		
			int v = pos.y + speed;
			pos.setLocation(pos.x, v);
			
		}
		if(left && !up && !right && !down){ // mov izquierda
				
				int v = pos.x - speed;
				pos.setLocation(v, pos.y);
				
		
		}
		if(right && !up && !down && !left){ // mov derecha
			
				int v = pos.x + speed;
				pos.setLocation(v, pos.y);
			
				
		}
		if(right && up && !down && !left){ // mov diagonal arrivaderecha
			
				int v = pos.x + speed;
				pos.setLocation(v, pos.y);
				v = pos.y - speed;
				pos.setLocation(pos.x, v);
				
			
			
		}
		if(left && up && !right && !down){ //mov diagonal izquierdaarriva
				
				int v = pos.x - speed;
				pos.setLocation(v, pos.y);
				v = pos.y - speed;
				pos.setLocation(pos.x, v);
				
			
		}
		if(right && !up && down && !left){ // mov derechaabajo
			
				int v = pos.x + speed;
				pos.setLocation(v, pos.y);
				v = pos.y + speed;
				pos.setLocation(pos.x, v);
				
			
		}
		if(left && !up && !right && down){ // mov izquierda abajo
					
				int v = pos.x - speed;
				pos.setLocation(v, pos.y);
				v = pos.y + speed;
				pos.setLocation(pos.x, v);
				
			
		}
		this.setLocation(pos);
	}
	public void vanish(){
		this.setVisible(false);
		juego=null;
	
	}
	public int getpot(){
		return potencia;
	}
	public int getspeed(){
		return speed;
	}
	public boolean impactohitbox(plane e){
		boolean cond1=false;
		boolean cond2=false;
		cond1=((this.getLocation().getX()<=(e.getLocation().getX()+(e.getWidth()))) && (this.getLocation().getX()>=(e.getLocation().getX())));
		cond2=((this.getLocation().getY()<=(e.getLocation().getY()+e.getHeight())) && (this.getLocation().getY()>=(e.getLocation().getY())));
		return (cond1 && cond2);
	}
}


